package com.neu.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.neu.mapper.ClazzMapper;
import com.neu.pojo.Clazz;
import com.neu.pojo.Emp;
import com.neu.pojo.PageResult;
import com.neu.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;


@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
//    @Override
//    public PageResult<Clazz> page(Integer page, Integer pageSize) {
//        //1.设置分页参数
//        PageHelper.startPage(page, pageSize);
//        //2.执行查询
//        List<Clazz> clazzList = clazzMapper.list();
//        //3.解析查询结果，并封装
//        Page<Clazz> p = (Page<Clazz>) clazzList;
//
//        return new PageResult<Clazz>(p.getTotal(),p.getResult());
//    }

    @Override
    public PageResult<Clazz> page(Integer page, Integer pageSize, String name, LocalDate begin, LocalDate end) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.执行查询
        List<Clazz> clazzList = clazzMapper.list(name,begin,end);
        //3.解析查询结果，并封装
        Page<Clazz> p = (Page<Clazz>) clazzList;

        return new PageResult<Clazz>(p.getTotal(),p.getResult());
    }

    @Override
    public void insert(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.insert(clazz);
    }

    @Override
    public void deleteById(Integer id) {
        clazzMapper.deleteById(id);
    }

    @Override
    public Clazz getById(Integer id) {
        Clazz clazz = clazzMapper.getById(id);
        return clazz;
    }

    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.update(clazz);

    }

    @Override
    public List<Clazz> findAll() {
        List<Clazz> clazzList = clazzMapper.findAll();
        return clazzList;
    }


}
